package com.ruoyi.deeplearn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.deeplearn.domain.DeepModelDeploy;
import com.ruoyi.deeplearn.service.IDeepModelDeployService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模型部署Controller
 *
 * @author 任伟伟
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/deeplearn/deploy")
public class DeepModelDeployController extends BaseController
{
    @Autowired
    private IDeepModelDeployService deepModelDeployService;

    /**
     * 查询模型部署列表
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:deploy:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeepModelDeploy deepModelDeploy)
    {
        startPage();
        List<DeepModelDeploy> list = deepModelDeployService.selectDeepModelDeployList(deepModelDeploy);
        return getDataTable(list);
    }

    /**
     * 导出模型部署列表
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:deploy:export')")
    @Log(title = "模型部署", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeepModelDeploy deepModelDeploy)
    {
        List<DeepModelDeploy> list = deepModelDeployService.selectDeepModelDeployList(deepModelDeploy);
        ExcelUtil<DeepModelDeploy> util = new ExcelUtil<DeepModelDeploy>(DeepModelDeploy.class);
        util.exportExcel(response, list, "模型部署数据");
    }

    /**
     * 获取模型部署详细信息
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:deploy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deepModelDeployService.selectDeepModelDeployById(id));
    }

    /**
     * 新增模型部署
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:deploy:add')")
    @Log(title = "模型部署", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeepModelDeploy deepModelDeploy)
    {
        return toAjax(deepModelDeployService.insertDeepModelDeploy(deepModelDeploy));
    }

    /**
     * 修改模型部署
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:deploy:edit')")
    @Log(title = "模型部署", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeepModelDeploy deepModelDeploy)
    {
        return toAjax(deepModelDeployService.updateDeepModelDeploy(deepModelDeploy));
    }

    /**
     * 删除模型部署
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:deploy:remove')")
    @Log(title = "模型部署", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deepModelDeployService.deleteDeepModelDeployByIds(ids));
    }
}
